<div class="good_choose_layer" style="display: none;"></div>
<div class="good_choose" style="display: none;z-index:999;">
    <div class="info">
         <div class="left">
             <img id="chooser_img" src="{php echo tomedia($goods['gimg']);}">
         </div>
         <div class="right">
				<!--<div><span style="color:#888;">库存:</span></div>-->
               	<div class="price" id="option_opricee">￥<span id="option_oprice">{php echo $goods['oprice']}</span></div>
               	<div class="price" id="option_gpricee">￥<span id="option_gprice">0</span></div>
        		<span id='stockcontainer' class="stock" style="float:left;margin-left:5px;"></span>
         </div>
        <div class="close" onclick="closechoose()"><i class="fa fa-remove-o"></i></div>
    </div>
    <div class="other">
	{if $goods['hasoption']==1}
    	{loop $specs $spec}
   	 	<input type='hidden' name="optionid[]" class='optionid optionid_{$spec['id']}' value="" title="{$spec['title']}">
        <div class="spec" style='float:left;display:block;height:30px;line-height:30px;overflow:hidden;text-overflow:ellipsis;margin-left:10px;padding:0'>{$spec['title']}</div>
            <span style="float:left;margin-left:8px;" class='spec_items options options_{$spec['id']}' specid='{$spec['id']}'>
            {loop $spec['items'] $o}
            <span class="property option option_{$spec['id']}" specid='{$spec['id']}' oid="{$o['id']}" sel='false'>{$o['title']}</span>
            <input type="hidden" name="thumb_{$o['id']}" id="thumb_{$o['id']}" value="{php echo tomedia($o['thumb'])}" />
            {/loop}
            </span>
    	{/loop}
		{/if}
    	{if $goods['one_limit']>1}
    	<span style="float:left;margin-left:8px; " class='spec_items options' id="in">
            <span style="margin-left: 10px;"><font color="#000000" size="2">选择数量</font></span>
			<div class="w-number" id="pro-view-7" style="float: right;">
				<div class="w-number-input" id="num" name="num" contenteditable="true">0</div>
				<a href="javascript:;" class="w-number-btn w-number-btn-plus" id="up">
					+
				</a>
				<a href="javascript:;" class="w-number-btn w-number-btn-minus" id="down">
					-
				</a>
			</div>
        </span>
        {/if}
    </div>
    <div class="close" onclick="closechoose()"><i class="fa fa-times-circle-o"></i></div>
    <div class="sub" id="nowbuy" style="background-color:#6fbfd8">确认</div>
</div>
<script>
	
	
	$(function () {
		 
	    $('.other-detail .detail-group:last').css("border-bottom", "0");
        $(".option,.optionimg").click(function () {
	        var specid = $(this).attr("specid");
            var oid = $(this).attr("oid");
            var thumb = $("#thumb_"+oid).val();
            if(thumb){
            	$("#chooser_img").attr("src",thumb);
            }
            $(".optionid_" + specid).val(oid);
            $(".options_" + specid + "  span").removeClass("current").attr("sel", "false");
            $(this).addClass("current").attr("sel", "true");
			
            var optionid = "";
            var stock = 0;
            var marketprice = 0;
            var productprice = 0;
            var buytype = $("#buytype").val();
            var ret = option_selected();

            if (ret.no == '') {
                var len = options.length;
                for (var i = 0; i < len; i++) {
                    var o = options[i];
                    var ids = ret.all.join("_");
                    if (o.specs == ids) {
                        optionid = o.id;
                        stock = o.stock;
                        marketprice = o.marketprice;
                        productprice = o.productprice;
						
                        break;
                    }
                }
				$("#optionid").val(optionid);
				//$("#option_gprice").html(marketprice);
				$("#option_gprice").html(productprice);
                $("#option_oprice").html(productprice);
                $("#in").show();
				//等选择规格后，给 增、减按钮加事件
			    $("#up").off('click').on('click',up_fun);
	            $("#down").off('click').on('click',down_fun);
				
				
			for (var key in Buy) {
			if (key in GuigeSelect) {
			//alert(JSON.stringify(GuigeSelect));
			  var jiage = queryGuigestr(key);
			  for (var i = 0; i< jiage.length; i++){
				  $("#num").text(GuigeSelect[key][jiage[i]]);			
			
    			  }
			  }			 
			}
			
			    $("#option_gpricee").hide();
                $("#option_opricee").show();
            }
        });
    });

    function buy() {                  //规格弹出框中的确定按钮
		$("#nowbuy").off("click");
		var ev=$(this).get(0);	
	   	var spec_items = document.getElementsByClassName("spec_items");
		var specLen = spec_items.length;
    	var select = true;
		var str = '';
		for (var i =0; i < specLen; i++) {	
			if (spec_items[i].getElementsByClassName("current").length>0) {
				var select = true;
				str += spec_items[i].getElementsByClassName("current")[0].innerHTML + '+';
                break;  
			}else{
				var select = false;
				break;
			}
		}
	
		str = str.slice(0,-1);  //str为规格颜色
		if (!select){
		  $.toast('请选择规格');
		  $("#nowbuy").on("click",buy);
		  return false;
		}
		$('.good_choose_layer').fadeOut(100);
		$('.good_choose').fadeOut(100); 
 	    
		
		
	  	plusNumber(ev,str);
			
        setTimeout($("#nowbuy").on("click",buy),2000);
		
		
	  /*  var ret = option_selected();
        if (ret.no != '') {
            $.toast('请选择'+ret.no + "!");
            return;
        }
        {if $goods['one_limit']>1}
		var inputnum = $("#num").val();
		{else}
		var inputnum = 1;
		{/if}
        var num = "{php echo $goods['gnum']}";
        var many_limit = $("#many_limit").val();
        var one_limit = $("#one_limit").val();
        var times = $("#times").val();
        inputnum = parseInt(inputnum);
        num = parseInt(num);
        many_limit = parseInt(many_limit);
        one_limit = parseInt(one_limit);
        times = parseInt(times);
        {if $goods['one_limit']>1}
	        if(isNaN(inputnum)){
	        	$.toast('数量错误!');
				return false;
	        }else{
	        	if(inputnum<0){
	        		$.toast('数量错误!');
					return false;
	        	}
	        	if(inputnum > num){
	        		$.toast('库存不足!');
					return false;
	        	}
	        	if(one_limit>1){
	        		if(inputnum > one_limit){
		        		$.toast('单次购买上限为：'+one_limit);
						return false;
		        	}
	        	}
	        	
	        }
        {/if}
		if(many_limit>=1){
	        		if(inputnum+times > many_limit){
		        		$.toast('单人购买总数为：'+many_limit);
						return false;
		        	}
	        	}
        var groupnum = $("#buytype").val();
        location.href = "{php echo app_url('order/orderconfirm')}" + "&optionid=" + $("#optionid").val() + "&groupnum=" + groupnum+"&num=" + inputnum;
		*/
    }
	
     	$("#nowbuy").on("click",buy);
	
</script>